package cn.wizzer.app.web.modules.controllers.platform.user.account;

import cn.wizzer.app.user.modules.services.account.UserRebateService;
import cn.wizzer.framework.page.Pagination;
import cn.wizzer.framework.util.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

/**
 * @author zl
 * @date 2020/6/16 14:59
 */
@IocBean
@At("/platform/user/account/income")
public class AccountIncomeController {

    @Inject
    @Reference
    private UserRebateService userRebateService;

    @At("")
    @Ok("beetl:/platform/user/account/income/index.html")
    @RequiresPermissions("user.account.income")
    public void index(HttpServletRequest req) {

    }

    /**
     * 查询返佣收益记录列表（分页）
     *
     * @param orderNo
     * @param fromUserSearch
     * @param toUserSearch
     * @param searchDate
     * @param pageNumber
     * @param pageSize
     * @return Object
     */
    @At
    @Ok("json:full")
    @RequiresPermissions("user.account.income")
    public Object data(@Param("conditionData") String conditionData,
                       @Param("orderNo") String orderNo,
                       @Param("fromUserSearch") String fromUserSearch,
                       @Param("toUserSearch") String toUserSearch,
                       @Param("searchDate") String[] searchDate,
                       @Param("pageNumber") int pageNumber,
                       @Param("pageSize") int pageSize) {
        Pagination pagination = userRebateService.listPage(conditionData, orderNo, fromUserSearch, toUserSearch, searchDate, pageNumber, pageSize);
        // 统计投注总额，根据搜索条件
        BigDecimal sum = userRebateService.searchSum(conditionData, orderNo, fromUserSearch, toUserSearch, searchDate);
        return Result.success().addData(Result.createMap("pagination", pagination, "sum", sum));

    }

}
